//
//  SecondViewController.swift
//  页面通信
//
//  Created by lanou on 16/11/7.
//  Copyright (c) 2016年 lanou. All rights reserved.
//

import UIKit
//定义协议
protocol secondProtocol{

    func translateString(str:String)
}

class SecondViewController: UIViewController {
//    声明从第一个页面传过来的字符串
    var oneStr:String?
//    定义一个传值闭包(给传过来的参数进行拼接)
//    返回类型 闭包名 (参数列表)  返回类型
    var closure:((str:String)->Int)?
//    声明代理
    var delegate:secondProtocol?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(oneStr)
        navigationItem.title = "控制器二"
//        改变视图的颜色
        view.backgroundColor = UIColor.cyanColor()
        
        
       let leftBtn = UIBarButtonItem(title: "back", style: .Plain, target: self, action: "backAction")
//       设置导航栏的左按钮
        navigationItem.leftBarButtonItem = leftBtn
    }
    func backAction(){
        closure!(str: "第二个页面")
//        页面返回是代理执行这个事件
        delegate?.translateString("secondVC")
        navigationController?.popViewControllerAnimated(true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
